<template>
  <div>
    <el-dialog title="配送单详情" :close-on-click-modal="false" :visible.sync="visible" fullscreen center>
      <el-row style="margin-bottom: 10px;">
        <el-link  style="margin-left:15px;" :href="printUrl" target="_blank" type="info"><el-button size="mini" type="info" @click="getPrintParams(dataForm.id)">打印单据</el-button></el-link>
      </el-row>
      <el-form :model="dataForm" ref="dataForm" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="配送单号" prop="deliverBillId">
              <el-input type="text"  placeholder="请输入内容" v-model="dataForm.deliverBillId"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="配送时间" prop="deliveryTime">
              <el-input type="text"  placeholder="请输入内容" v-model="dataForm.deliveryTime"></el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="配送人" prop="userName">
              <el-input type="text"  placeholder="请输入内容" v-model="dataForm.userName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="配送门店" prop="deptName">
              <el-input type="text"  placeholder="请输入内容" v-model="dataForm.deptName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="handleSelectionChange">
       <!-- <el-table-column type="selection" width="40"></el-table-column>-->
        <el-table-column prop="saleBillId" label="配镜单号">
          <template slot-scope="scope">
            <el-button type="text" @click="checkDetailByOrder(scope.row.saleBillId)">{{scope.row.saleBillId}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="customerName" label="顾客姓名"></el-table-column>
        <el-table-column prop="takeMirroDeptName" label="取镜门店"></el-table-column>
        <el-table-column prop="takeMirroTime" label="取镜时间"></el-table-column>
        <el-table-column prop="saleType" label="配镜类型">
          <template slot-scope="scope">
            {{getSaleType(scope.row.saleType)}}
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">关闭</el-button>
      </span>
      <order-info v-if="infoVisible" ref="infoDialog"></order-info>
    </el-dialog>

  </div>
</template>

<script>
    import { getDeliveryObj } from '@/api/eims/optician/delivery'
    import {mapGetters} from 'vuex'
    import { remote } from '@/api/admin/dict'
    import OrderInfo from '@/views/eims/optician/glassesinfo/detail'
    export default {
        data () {
            return {
                visible: false,
                infoVisible:false,
                printUrl: '',
                dataForm: {
                    deliveryDetailList: []
                },
               // verify: false,
                dataList: [],
                saleTypeData: [],
                dataListLoading:false
            }
        },
        computed: {
            ...mapGetters(['bizData', 'keyCollapse'])
        },
        components: {
            OrderInfo
        },
        methods: {
            init (id) {
                this.dataForm.deliveryDetailList = []
                this.dataList = []
                this.dataForm.id = id || 0
                remote('sale_type').then(result => {
                  this.saleTypeData = result.data.data
                })
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    if (this.dataForm.id) {
                        getDeliveryObj(this.dataForm.id).then(response => {
                          if(response.data.code == '0'){
                            this.dataForm = response.data.data
                            this.dataList = response.data.data.deliveryDetailList
                          }else{
                            this.$message.error(response.data.msg)
                          } 
                        })
                    }
                })
            },
            //  查看配镜单详情
            checkDetailByOrder(order) {
                this.infoVisible = true;
                this.$nextTick(() => {
                    this.$refs.infoDialog.init('', order, '配镜单详情');
                });
            },
            //获取配镜类型枚举
            getSaleType: function (value) {
                let obj = {};
                obj = this.saleTypeData.find((item)=>{
                    return item.value == value;
                });
                return obj.label;
            },
            // 多选表格表格变化事件
            handleSelectionChange (val) {
                this.selectionList = val
            },
            //  打印单据
            getPrintParams(id) {
              let params = '/deliveryPrint.cpt&id='
              this.printUrl = this.bizData.printUrl + params + id
            }
        }
    }
</script>
